package interview.volatiled;


/**
 *   验证volatile禁止重排序
 * */
class ReSort{

    public  volatile  int number=1;
    public  volatile  boolean flag=false;

    public void fun1(){
        number=5;
        flag=true;
    }

    public void fun2(){
       // if (flag){
            number=number+1;
            System.out.println("******"+number);
       // }
    }
}

public class VolatileDemo3 {
    public static void main(String[] args) {

        ReSort reSort = new ReSort();
        new Thread(()->{
            reSort.fun2();
        },"BBB").start();
        new Thread(()->{
            reSort.fun1();
        },"AA").start();




    }
}
